package view;

import logic.*;
import java.util.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;


/**
 * This class gives a representation of the field in a Histogram.	
 * @author Vossen en Konijnen group 2
 *
 */
		public class HistogramView extends AbstractView {

		private int rabbitCount;
		private int hunterCount;
		private int duckCount;
		private int foxCount;
		private int grassCount;
		private FieldStats stats;
		
		/**
		 * Makes a new Histogram and adds it to the list of views in the model.
		 * @param simulator
		 */
		public HistogramView(Simulator simulator) {
			super(simulator);
			setSize(200, 200);
		}

		
		/**
		 * Paint's the Histogram.
		 */
		public void paintComponent(Graphics g) {
			g.setColor(new Color(238,238,238));
			Dimension d=getSize();
			g.fillRect(0,0,d.width,d.height);
			stats = getModel().getStats();
			HashMap hashmap = stats.getHashMap();
			try{
				foxCount = ((Counter) hashmap.get(Fox.class)).getCount();
				duckCount = ((Counter) hashmap.get(Duck.class)).getCount();
				hunterCount = ((Counter) hashmap.get(Hunter.class)).getCount();
				rabbitCount = ((Counter) hashmap.get(Rabbit.class)).getCount();
				grassCount = ((Counter) hashmap.get(Grass.class)).getCount();
			}	
			catch(Exception e)
			{
				
			}
			
			g.setColor(Color.BLUE);
			g.fillRect(10, 250, 50, -foxCount);
			g.setColor(Color.BLACK);
			g.fillRect(61, 250, 50, -hunterCount);
			g.setColor(Color.RED);
			g.fillRect(112, 250, 50, -duckCount);
			g.setColor(Color.ORANGE);
			g.fillRect(163, 250, 50, -rabbitCount);
			g.setColor(Color.GREEN);
			g.fillRect(214, 250, 50, -grassCount);
	}



}
